import 'package:flutter/material.dart';
import 'package:proj_shop/roots/tutorial/navigator_service.dart';
import 'package:proj_shop/roots/widget/tutorial_update_dialog.dart';

class TutorialPage1 extends StatefulWidget {
  @override
  _TutorialPage1State createState() => _TutorialPage1State();
}

class _TutorialPage1State extends State<TutorialPage1> {
  @override
  void initState() {
    updateAlert(context);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Page1')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            RaisedButton(
              onPressed: () {
                print(context.size.width);
              },
              child: Text('Push to Page2'),
            ),
            RaisedButton(
              onPressed: () {
                Navigator.of(context).pushNamed('/page3');
              },
              child: Text('Push to Page3'),
            ),
            RaisedButton(
              onPressed: () {
                Navigator.of(context).pushNamed('/page6');
              },
              child: Text('Push to Unkonwn'),
            ),
          ],
        ),
      ),
    );
  }
}

Future<void> updateAlert(BuildContext context) async {
  Future.delayed(Duration(seconds: 2)).then((value) {
    // 显示升级弹窗
    showDialog(
      context: context,
      barrierDismissible: false, // 点击空白区域对话框不消失
      builder: (_) {
        return WillPopScope(
          child: TutorialUpdateDialog(),
          onWillPop: () {
            return;
          },
        );
      },
    );
  });
}
